# Maintainer: Patrick Stewart <patstew@gmail.com>

_realname=jupyter_console
pkgbase=mingw-w64-python3-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=6.0.0
pkgrel=3
pkgdesc="A terminal-based console frontend for Jupyter kernels. (mingw-w64)"
arch=('any')
url="https://jupyter.org/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python3"
         "${MINGW_PACKAGE_PREFIX}-python3-jupyter_core"
         "${MINGW_PACKAGE_PREFIX}-python3-jupyter_client"
         "${MINGW_PACKAGE_PREFIX}-python3-colorama")
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/jupyter/jupyter_console/archive/v${pkgver}.tar.gz")
install=${_realname}3-${CARCH}.install
sha256sums=('5cafb1a3b845dbab143c182f270f66396e1ef6a322c6bee7e6f4b0bf85fcf69e')

prepare() {
  cd "${srcdir}"
  rm -rf $"python3-build-${CARCH}" | true
  cp -r "${_realname}-${pkgver}" "python2-build-${CARCH}"
  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
  export LC_CTYPE=en_US.UTF-8
}

build() {
    msg "Python 3 build for ${CARCH}"  
    cd "${srcdir}/python2-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python3 setup.py build
}


all_install() {

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/${1} setup.py install \
    --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=0  --skip-build

  find "${pkgdir}/" -name "*.pyc" -delete
  find "${pkgdir}/" -type d -empty -delete

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*; do
    sed -e "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i ${_f}
  done
}

package() {
  local interpreter=python3
  depends=("${MINGW_PACKAGE_PREFIX}-python3"
           "${MINGW_PACKAGE_PREFIX}-python3-jupyter_core"
           "${MINGW_PACKAGE_PREFIX}-python3-jupyter_client"
           "${MINGW_PACKAGE_PREFIX}-python3-colorama")

  cd "${srcdir}/python2-build-${CARCH}"
  all_install ${interpreter}

  install -Dm644 "COPYING.md" "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE"
}

